package logic

import (
	"context"
	"month2/C/rpc_C/model/mysql"

	"month2/C/rpc_C/internal/svc"
	"month2/C/rpc_C/order"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsListLogic {
	return &GoodsListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodsListLogic) GoodsList(in *order.GoodsListRequest) (*order.GoodsListResponse, error) {
	var goods []*mysql.Goods1
	mysql.DB.Order("like_count desc").Find(&goods)
	var list []*order.GoodsList
	for _, good := range goods {
		goodsList := order.GoodsList{
			GoodsName:  good.GoodsName,
			GoodsPrice: float32(good.GoodsPrice),
			GoodsNum:   int64(good.GoodsNum),
			GoodsImg:   good.GoodsImg,
			LikeCount:  int64(good.LikeCount),
		}
		list = append(list, &goodsList)
	}
	return &order.GoodsListResponse{List: list}, nil
}
